package com.wjq.service;

import com.alibaba.fastjson.JSON;
import com.wjq.entity.ChoiceQuestion;
import com.wjq.mapper.ChoiceQuestionMapper;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChoiceQuestionServiceImpl implements ChoiceQuestionService{

    @Autowired
    ChoiceQuestionMapper choiceQuestionMapper;

    /**
     *问卷id
     * @param
     * @return 该问卷所有选择题
     */
    @Override
    public List<ChoiceQuestion> getQuestions(Integer id){
        List<ChoiceQuestion> choiceQuestions = choiceQuestionMapper.queryList(id);
        return choiceQuestions;
    }

    @Override
    public void updateQuestion(ChoiceQuestion question){
//        String s ="{\"id\":\"2\",\"description\":\"下面哪句话出自《孟子》？\"," +
//                "\"questionnaire_id\":\"1\",\"serial_num\":\"5\", \"multi_select\":\"0\"}";
        System.out.println(question.getId() + " " + question.getDescription() + " " + question.getQuestionnaireId() + " " + question.getSerialNum() + "****");
        choiceQuestionMapper.updateChoiceQuestion(question);
    }

    @Override
    public void addQuestion(ChoiceQuestion choiceQuestion) {
        choiceQuestionMapper.addChoiceQuestion(choiceQuestion);
    }

    @Override
    public int getQuestionId(ChoiceQuestion choiceQuestion) {
        return choiceQuestionMapper.getChoiceQuestionId(choiceQuestion);
    }

    @Override
    public void deleteQuestopn(Integer id) {
        choiceQuestionMapper.deleteChoiceQuestionById(id);
    }

    @Override
    public ChoiceQuestion selectChoiceQuestion(Integer id) {
        return  choiceQuestionMapper.selectChoiceQuestionById(id);
    }

}
